#include <iostream>
#include <map>
using namespace std;
int main()
{
	map<char, int> hash_parent;
	map<int, int> count;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		char c; cin >> c;
		int p; cin >> p;
		hash_parent[c] = p;
		count[p]++;
	}
	char tgt; cin >> tgt;
	if (hash_parent.count(tgt))
		cout << count[hash_parent[tgt]];
	else
		cout << 0;
	return 0;
}